package com.xxp.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxp.controller.request.HistoryRequest;
import com.xxp.entity.Fuzhou;
import com.xxp.entity.History;
import com.xxp.entity.Travel;
import com.xxp.mapper.HistoryMapper;
import com.xxp.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    private HistoryMapper historyMapper;
    @Override
    public Fuzhou selectByFzId(Integer id) {
        return  historyMapper.selectByFzId(id);

    }

    @Override
    public List<History> selectName() {
       return historyMapper.selectName();
    }

    @Override
    public History selectByID(Integer id) {
       return historyMapper.selectById(id);
    }

    @Override
    public void updateViews(History history) {
        Integer views = history.getViews();
        views++;
        history.setViews(views);
        historyMapper.updateView(history);
    }

    @Override
    public Object findAll(HistoryRequest historyRequest) {
        PageHelper.startPage(historyRequest.getPageNum(),historyRequest.getPageSize());
        List<History> all = historyMapper.findAll(historyRequest);
        return new PageInfo<>(all);
    }

    @Override
    public void updateHistory(History history) {
        historyMapper.updateHistory(history);
    }
}
